package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class BaseDao {
	private static Connection conn;
	private static PreparedStatement prep;
	private static ResultSet rs;
	private static String Driver="com.mysql.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/easybuy";
	private static String user="root";
	private static String password="zyc";
	public static Connection getconnection(){
		try {
			if (conn == null || conn.isClosed()) {
			Class.forName(Driver);
			conn=DriverManager.getConnection(url, user, password);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return conn;
	}
	public static void closeAll(ResultSet rs,PreparedStatement prep,Connection conn){
			try {
				if(rs!=null){
				rs.close();
				}
				if(prep!=null){
					prep.close();
				}
				if(conn!=null){
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		
		
	}
}
